package com.xxxy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxy.commonResult.CommonResult;
import com.xxxy.commonResult.CommonResultPage;
import com.xxxy.dao.OperationLogDao;
import com.xxxy.log.Log;
import com.xxxy.model.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author sjh
 * @date 2022/2/6 14:08
 */
@RestController
@Api(tags = "系统日志")
@RequestMapping("/log")
public class OperationLogController {

    @Autowired
    OperationLogDao operationLogDao;

    @Log(module = "系统日志", description = "获取系统日志列表")
    @PostMapping(value = "/list")
    @ApiOperation(value = "系统日志列表")
//    @RequiresRoles(value={"ADMIN","TEACHER"},logical = Logical.OR)
    public CommonResult<CommonResultPage> list(@ApiParam("页数") @RequestParam(defaultValue = "1") Integer page,
                                               @ApiParam("一页条数") @RequestParam(defaultValue = "10") Integer size) {
        PageHelper.startPage(page, size);
        List<OperationLog> operationLogList = operationLogDao.selectList(null);
        PageInfo<OperationLog> pageInfo = new PageInfo<>(operationLogList);
        CommonResultPage result = new CommonResultPage();
        result.setTotal(pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return CommonResult.success(result);
    }
}
